// pages/morejob/taskdestail/taskdestail.js
Page({
  data: {
    bottomHeight: getApp().globalData.bottomHeight,
    detail: {}
  },
  onLoad: function (options) {
    this.setData({
      id: options.id,
    });
  },
  onShow: function () {
    this.getDetail();
  },
  onShareAppMessage() {},
  getDetail() {
    getApp().globalData.http.detail({
      id: this.data.id
    }).then(res => {
      let tmp = res.data;
      tmp.imgUrls = tmp.imgUrls.split(",");
      this.setData({
        detail: tmp
      });
    });
  },
  denounce() {
    getApp().globalData.vant.dialog.confirm({
      title: "确定举报吗?",
      message: "任务存在欺诈、色情低俗、不实信息、违法犯罪等问题，您可以发起举报~",
      confirmButtonText: "确定",
      closeOnClickOverlay: true
    }).then(() => {
      wx.navigateTo({
        url: "/pages/morejob/denounce/denounce?postId=" + this.data.detail.id + "&userId=" + this.data.detail.userId,
      });
    });
  },
  getOrder() {
    getApp().globalData.http.userInfo().then(res => {
      if (!wx.getStorageSync("isFirstOrder")) {
        getApp().globalData.vant.dialog.confirm({
          title: "温馨提示",
          message: "如果抢到派单不完成，将会造成资源浪费，超过3次将封号处理。",
          confirmButtonText: "确定",
          closeOnClickOverlay: true,
          showCancelButton: false,
          className: "dialog-red",
        }).then(() => {
          wx.setStorageSync("isFirstOrder", 1);
          this.taskOrderTake(res.data.takeOrderAuth);
        });
      } else {
        this.taskOrderTake(res.data.takeOrderAuth);
      }
    });
    return
    getApp().globalData.vant.dialog.confirm({
      title: "温馨提示",
      message: "已达今日接单上限，请升级为正式会员。",
      // message: "体验期已过，请升级为正式会员。",
      cancelButtonText: "关闭",
      confirmButtonText: "确定",
      closeOnClickOverlay: true,
      showCancelButton: true,
      className: "dialog-red",
    }).then(() => {
      wx.navigateTo({
        url: "/pages/my/level/level",
      });
    });

    getApp().globalData.vant.dialog.confirm({
      title: "封号通知",
      message: "您已连续3次抢单后未完成，造成了资源浪费，依据平台规定，现对该账号进行封号。如需解封，请在“我的-设置-解封申请”进行操作。",
      messageAlign: "left",
      confirmButtonText: "好的",
      closeOnClickOverlay: true,
      showCancelButton: false,
      className: "dialog-red",
    }).then(() => {});
  },
  taskOrderTake(takeOrderAuth) {
    if (takeOrderAuth == 0) {
      getApp().globalData.vant.dialog.confirm({
        title: "认证提示",
        message: "好遗憾呀，该任务只有认证用户才可以抢单，赶快去认证吧~",
        confirmButtonText: "去认证",
        closeOnClickOverlay: true,
        showCancelButton: false
      }).then(() => {
        wx.navigateTo({
          url: "/pages/morejob/certify/certify",
        });
      });
    } else {
      getApp().globalData.http.taskOrderTake({
        id: this.data.detail.id,
        userId: this.data.detail.userId
      }).then(res => {
        getApp().globalData.vant.toast({
          type: "success",
          message: res.msg,
          duration: 1000,
          onClose: () => {
            wx.redirectTo({
              url: "/pages/my/rushorder/rushorder"
            });
          },
        });
      }).catch(e => {
        getApp().globalData.vant.toast.fail(e.msg);
      });
    }
  },
  previewImg(e) {
    let arr = e.currentTarget.dataset.img;
    let current = e.currentTarget.dataset.current;
    getApp().globalData.util.previewImage(arr, current);
  }
})